﻿
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class UToggle :MonoBehaviour,IPointerClickHandler
{
    public Graphic Background;
    public Graphic Checkmark;
    [SerializeField]
    private bool _isOn = false;

    public bool isOn
    {
        get
        {
            return _isOn;
        }
        set
        {
            _isOn = value;
            Checkmark.gameObject.SetActive(_isOn);
        }
    }

    public Action<UToggle,bool> OnValueChanged;

    void Start()
    {
        Checkmark.gameObject.SetActive(_isOn);
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        isOn = !_isOn;
        Checkmark.gameObject.SetActive(_isOn);
        if (OnValueChanged != null)
        {
            OnValueChanged(this, _isOn);
        }
    }
}
